package com.fantabest.frontend.client.widget;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.widget.Layout;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.fantabest.common.client.FantaBestConstants;
import com.fantabest.common.client.FantaBestMessages;
import com.fantabest.common.client.RegistryKeys;
import com.fantabest.common.client.widget.PlayersPanel;
import com.fantabest.common.entity.Manager;
import com.fantabest.common.entity.Season;

public class MarketPanel extends LayoutContainer {

	private FantaBestConstants constants = Registry.get(RegistryKeys.CONSTANTS);
	private FantaBestMessages messages = Registry.get(RegistryKeys.MESSAGES);	
	
	public MarketPanel() {
		super();
		initUI();
	}

	public MarketPanel(Layout layout) {
		super(layout);
		initUI();
	}

	private void initUI()	{
		this.setLayout(new ColumnLayout());
		
		LayoutContainer left = new LayoutContainer();
		left.setStyleAttribute("paddingRight", "10px");
		Season season = Registry.get(RegistryKeys.SEASON_ENTITY);
		left.addText("<div class=\"centerPanelTitle\">"+messages.seasonPlayers(season.getTitle())+"</div>");
		
		LayoutContainer right = new LayoutContainer();
		Manager manager = Registry.get(RegistryKeys.MANAGER_LOGGED_IN);
		right.addText("<div class=\"centerPanelTitle\">"+messages.playerMarket(manager.getNickname())+"</div>");
		
		ColumnData leftData = new ColumnData();
		leftData.setWidth(.5);
		this.add(left, leftData);

		ColumnData rightData = new ColumnData();
		rightData.setWidth(.5);
		this.add(right, rightData);
		
//		LEFT
		left.add(new PlayersPanel());

//		RIGHT
		FormLayout layout = new FormLayout();
		layout.setLabelAlign(LabelAlign.RIGHT);
		LayoutContainer teamInfo = new LayoutContainer(layout);
		
		FormData formData = new FormData();
		

		TextField<String> teamName = new TextField<String>();
		teamName.setFieldLabel(constants.teamName());
		teamName.setAllowBlank(false);
		teamName.setAutoValidate(true);
		teamName.setMaxLength(30);
		teamName.getMessages().setBlankText(messages.required(constants.teamName()));

		TextField<String> initialBudget = new TextField<String>();
		initialBudget.setFieldLabel(constants.initialBudget());
		initialBudget.setAutoValidate(true);
		initialBudget.setMaxLength(30);		
		initialBudget.setWidth(20);
		
		TextField<String> remainingBudget = new TextField<String>();
		remainingBudget.setFieldLabel(constants.remainingBudget());
		remainingBudget.setAutoValidate(true);
		remainingBudget.setMaxLength(30);
		remainingBudget.setWidth(20);
		
		teamInfo.add(teamName);
		formData.setWidth(40);
		teamInfo.add(initialBudget,formData);
		teamInfo.add(remainingBudget,formData);
		
		right.add(teamInfo);
		right.add(new TeamPlayersPanel());
		this.layout(true);

	}
}
